<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2021/3/11 0011 10:21
 * Describe: 企业微信服务 - 客户管理类
 */

namespace app\common\server\corp;

use think\exception\ValidateException;

class Client extends Base
{
    /**
     * @var string 添加客户标签
     */
    private $addClientTagUrl = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token=%s';

    /**
     * 添加客户标签
     * @link https://work.weixin.qq.com/api/doc/90001/90143/92697
     * @param string $corpId 企业微信corpId 非主键ID
     * @param string $userId 添加外部联系人的userid
     * @param string $externalUserId 外部联系人userid
     * @throws ValidateException
     */
    public function addClientTag(string $corpId, string $userId, string $externalUserId): void
    {
        $res = $this->curlFn(sprintf($this->addClientTagUrl, (new Token())->getAuthCorpAccessToken($corpId)), [
            'userid' => $userId,
            'external_userid' => $externalUserId,
            'add_tag' => (new Tag())->getCorpDefaultTagId($corpId)
        ], true);
        $this->setResponse($res);
    }

}